//
//  HJNavigationController.swift
//  WeiBo
//
//  Created by 韩俊 on 15/12/5.
//  Copyright © 2015年 HanJun. All rights reserved.
//

import UIKit

class HJNavigationController: UINavigationController,UIGestureRecognizerDelegate{
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.interactivePopGestureRecognizer?.delegate = self
        
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count != 0 {
            
            var title: String = "返回"
            
            if childViewControllers.count == 1 {
                
                title = childViewControllers.first?.title ?? title
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem( imgName: "navigationbar_back_withtext", title: title, target: self, action: "back")
            
            //隐藏底部 tabbar
            viewController.hidesBottomBarWhenPushed = true
            
        }
        
        super.pushViewController(viewController, animated: true)
        
        
    }
    @objc private func back() {
        
        popViewControllerAnimated(true)
    }
    
    // MARK: - UIGestureRecognizerDelegate
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
      
        return childViewControllers.count != 1
    }
    

}
